package com.yanqu.road.server.cmd.strongholdwar;

import com.yanqu.road.entity.activity.stronghold.StrongholdSilverDonate;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.StrongholdWarCrossProto;
import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.strongholdwar.StrongholdWarMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;

import java.util.List;

@Cmd(code = CrossProtocol.C_CROSS_STRONGHOLD_DONATE_SILVER_DETAIL,desc = "")
public class CrossStrongholdMemberDonateSilverDetailCmd extends CrossUnionCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        StrongholdWarCrossProto.StrongholdCrossDonateSilverDetailReqMsg reqMsg = StrongholdWarCrossProto.StrongholdCrossDonateSilverDetailReqMsg.parseFrom(packet.getBytes());
        int activityId = reqMsg.getActivityId();
        String unionId = reqMsg.getUnionId();
        StrongholdWarProto.StrongholdMemberSilverDonateDataRespMsg.Builder resp = StrongholdWarProto.StrongholdMemberSilverDonateDataRespMsg.newBuilder();
        List<StrongholdSilverDonate> detaolList = StrongholdWarMgr.getSilverDonateDetail(activityId, unionId);
        for (StrongholdSilverDonate silverDonate : detaolList) {
            StrongholdWarProto.SilverDonateDataMsg.Builder builder = StrongholdWarProto.SilverDonateDataMsg.newBuilder();
            builder.setUserInfo(PlayerBasePb.parsePlayerBaseTempMsg(CrossUserMgr.getUserBaseInfo(silverDonate.getUserId())));
            builder.setValue(silverDonate.getNum().toString());
            resp.addData(builder);
        }
        YanQuMessage message = YanQuMessageUtils.buildMessage(ClientProtocol.U_STRONGHOLD_WAR_MEMBER_SILVER_DONATE, resp);
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), message);
    }

    @Override
    public void sendData() {

    }
}
